<template>
  <div class="app-container">
    <el-form
      :model="queryParamsEng"
      ref="queryFormEng"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="工程名称" prop="enginName">
        <el-input
          v-model="queryParamsEng.enginName"
          placeholder="请输入工程名称"
          clearable
          size="small"
          @keyup.enter.native="handleQueryEng"
        />
      </el-form-item>
      <el-form-item label="开工时间">
        <el-date-picker
          v-model="daterangeStartTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="竣工时间">
        <el-date-picker
          v-model="daterangeCompletTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryEng">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQueryEng">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAddEng"
          v-hasPermi="['system:engin:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdateEng"
          v-hasPermi="['system:engin:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDeleteEng"
          v-hasPermi="['system:engin:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExportEng"
          v-hasPermi="['system:engin:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getListEng"></right-toolbar>
    </el-row>

    <el-table :data="enginList" @selection-change="handleSelectionChangeEng">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="enginId" />
      <el-table-column label="工程分类号" align="center" prop="enginClassifiNum" />
      <el-table-column label="档号" align="center" prop="enginFileNum" />
      <el-table-column label="工程名称" align="center" prop="enginName" />
      <el-table-column label="单位工程名称" align="center" prop="unitProjectName" />
      <el-table-column label="工程地点" align="center" prop="projectLocation" />
      <el-table-column label="建设单位" align="center" prop="buildUnit" />
      <el-table-column label="施工单位" align="center" prop="constructiUnit" />
      <el-table-column label="立项批准单位" align="center" prop="projectApproveUnit" />
      <el-table-column label="设计单位" align="center" prop="designUnit" />
      <el-table-column label="勘察单位" align="center" prop="surveyUnit" />
      <el-table-column label="监理单位" align="center" prop="supervUnit" />
      <el-table-column label="质量安全监督单位" align="center" prop="qualitySupervUnit" />
      <el-table-column label="立项批准文" align="center" prop="projectApprovalNum" />
      <el-table-column label="工程规划许可证号" align="center" prop="enginplanPermitNum" />
      <el-table-column label="用地规划许可证号" align="center" prop="landplanPermitNum" />
      <el-table-column label="用地许可证号" align="center" prop="landusePermitNum" />
      <el-table-column label="施工许可证号" align="center" prop="constructiPermitNum" />
      <el-table-column label="规划许可证号" align="center" prop="planPermitNum" />
      <el-table-column label="总用地面积" align="center" prop="totalLandArea" />
      <el-table-column label="总建筑面积" align="center" prop="totalBuildArea" />
      <el-table-column label="建筑面积" align="center" prop="buildArea" />
      <el-table-column label="开工时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="竣工时间" align="center" prop="completTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.completTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工程预算" align="center" prop="projectBudget" />
      <el-table-column label="工程决算" align="center" prop="projectFinalAccounts" />
      <el-table-column label="案卷数" align="center" prop="filesCounts" />
      <el-table-column label="文字卷数" align="center" prop="textVolumes" />
      <el-table-column label="图纸卷数" align="center" prop="drawCounts" />
      <el-table-column label="保管期限" align="center" prop="storageTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.storageTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="密级" align="center" prop="secretLevel" />
      <el-table-column label="进馆日期" align="center" prop="entryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="移交单位" align="center" prop="handoverUnit" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120px"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateEng(scope.row)"
            v-hasPermi="['system:engin:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDeleteEng(scope.row)"
            v-hasPermi="['system:engin:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="totalEng>0"
      :total="totalEng"
      :page.sync="queryParamsEng.pageNum"
      :limit.sync="queryParamsEng.pageSize"
      @pagination="getListEng"
    />

    <!-- 添加或修改项目工程管理对话框 -->
    <el-dialog :titleEng="titleEng" :visible.sync="openEng" width="500px" append-to-body>
      <el-form ref="formEng" :model="formEng" :rules="rulesEng" label-width="80px">
        <el-form-item label="工程分类号" prop="enginClassifiNum">
          <el-input v-model="formEng.enginClassifiNum" placeholder="请输入工程分类号" />
        </el-form-item>
        <el-form-item label="档号" prop="enginFileNum">
          <el-input v-model="formEng.enginFileNum" placeholder="请输入档号" />
        </el-form-item>
        <el-form-item label="工程名称" prop="enginName">
          <el-input v-model="formEng.enginName" placeholder="请输入工程名称" />
        </el-form-item>
        <el-form-item label="单位工程名称" prop="unitProjectName">
          <el-input v-model="formEng.unitProjectName" placeholder="请输入单位工程名称" />
        </el-form-item>
        <el-form-item label="工程地点" prop="projectLocation">
          <el-input v-model="formEng.projectLocation" placeholder="请输入工程地点" />
        </el-form-item>
        <el-form-item label="建设单位" prop="buildUnit">
          <el-input v-model="formEng.buildUnit" placeholder="请输入建设单位" />
        </el-form-item>
        <el-form-item label="施工单位" prop="constructiUnit">
          <el-input v-model="formEng.constructiUnit" placeholder="请输入施工单位" />
        </el-form-item>
        <el-form-item label="立项批准单位" prop="projectApproveUnit">
          <el-input v-model="formEng.projectApproveUnit" placeholder="请输入立项批准单位" />
        </el-form-item>
        <el-form-item label="设计单位" prop="designUnit">
          <el-input v-model="formEng.designUnit" placeholder="请输入设计单位" />
        </el-form-item>
        <el-form-item label="勘察单位" prop="surveyUnit">
          <el-input v-model="formEng.surveyUnit" placeholder="请输入勘察单位" />
        </el-form-item>
        <el-form-item label="监理单位" prop="supervUnit">
          <el-input v-model="formEng.supervUnit" placeholder="请输入监理单位" />
        </el-form-item>
        <el-form-item label="质量安全监督单位" prop="qualitySupervUnit">
          <el-input v-model="formEng.qualitySupervUnit" placeholder="请输入质量安全监督单位" />
        </el-form-item>
        <el-form-item label="立项批准文" prop="projectApprovalNum">
          <el-input v-model="formEng.projectApprovalNum" placeholder="请输入立项批准文" />
        </el-form-item>
        <el-form-item label="工程规划许可证号" prop="enginplanPermitNum">
          <el-input v-model="formEng.enginplanPermitNum" placeholder="请输入工程规划许可证号" />
        </el-form-item>
        <el-form-item label="用地规划许可证号" prop="landplanPermitNum">
          <el-input v-model="formEng.landplanPermitNum" placeholder="请输入用地规划许可证号" />
        </el-form-item>
        <el-form-item label="用地许可证号" prop="landusePermitNum">
          <el-input v-model="formEng.landusePermitNum" placeholder="请输入用地许可证号" />
        </el-form-item>
        <el-form-item label="施工许可证号" prop="constructiPermitNum">
          <el-input v-model="formEng.constructiPermitNum" placeholder="请输入施工许可证号" />
        </el-form-item>
        <el-form-item label="规划许可证号" prop="planPermitNum">
          <el-input v-model="formEng.planPermitNum" placeholder="请输入规划许可证号" />
        </el-form-item>
        <el-form-item label="总用地面积" prop="totalLandArea">
          <el-input v-model="formEng.totalLandArea" placeholder="请输入总用地面积" />
        </el-form-item>
        <el-form-item label="总建筑面积" prop="totalBuildArea">
          <el-input v-model="formEng.totalBuildArea" placeholder="请输入总建筑面积" />
        </el-form-item>
        <el-form-item label="建筑面积" prop="buildArea">
          <el-input v-model="formEng.buildArea" placeholder="请输入建筑面积" />
        </el-form-item>
        <el-form-item label="开工时间" prop="startTime">
          <el-date-picker
            clearable
            size="small"
            v-model="formEng.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择开工时间"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="竣工时间" prop="completTime">
          <el-date-picker
            clearable
            size="small"
            v-model="formEng.completTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择竣工时间"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="工程预算" prop="projectBudget">
          <el-input v-model="formEng.projectBudget" placeholder="请输入工程预算" />
        </el-form-item>
        <el-form-item label="工程决算" prop="projectFinalAccounts">
          <el-input v-model="formEng.projectFinalAccounts" placeholder="请输入工程决算" />
        </el-form-item>
        <el-form-item label="案卷数" prop="filesCounts">
          <el-input v-model="formEng.filesCounts" placeholder="请输入案卷数" />
        </el-form-item>
        <el-form-item label="文字卷数" prop="textVolumes">
          <el-input v-model="formEng.textVolumes" placeholder="请输入文字卷数" />
        </el-form-item>
        <el-form-item label="图纸卷数" prop="drawCounts">
          <el-input v-model="formEng.drawCounts" placeholder="请输入图纸卷数" />
        </el-form-item>
        <el-form-item label="保管期限" prop="storageTime">
          <el-date-picker
            clearable
            size="small"
            v-model="formEng.storageTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择保管期限"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="密级" prop="secretLevel">
          <el-input v-model="formEng.secretLevel" placeholder="请输入密级" />
        </el-form-item>
        <el-form-item label="进馆日期" prop="entryDate">
          <el-date-picker
            clearable
            size="small"
            v-model="formEng.entryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择进馆日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="移交单位" prop="handoverUnit">
          <el-input v-model="formEng.handoverUnit" placeholder="请输入移交单位" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormEng">确 定</el-button>
        <el-button @click="cancelEng">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listEngin,
  getEngin,
  delEngin,
  addEngin,
  updateEngin
} from "@/api/system/engin";

export default {
  name: "Engin",
  data() {
    return {
      // 选中数组
      idsEng: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      totalEng: 0,
      // 项目工程管理表格数据
      enginList: [],
      // 弹出层标题
      titleEng: "",
      // 是否显示弹出层
      openEng: false,
      // 预留字段15时间范围
      daterangeStartTime: [],
      // 预留字段15时间范围
      daterangeCompletTime: [],
      // 预留字段15时间范围
      daterangeStorageTime: [],
      // 预留字段15时间范围
      daterangeEntryDate: [],
      // 预留字段15时间范围
      daterangeCreateTime: [],
      // 预留字段15时间范围
      daterangeUpdateTime: [],
      // 查询参数
      queryParamsEng: {
        pageNum: 1,
        pageSize: 5,
        enginClassifiNum: null,
        enginFileNum: null,
        enginName: null,
        unitProjectName: null,
        projectLocation: null,
        buildUnit: null,
        constructiUnit: null,
        projectApproveUnit: null,
        designUnit: null,
        surveyUnit: null,
        supervUnit: null,
        qualitySupervUnit: null,
        projectApprovalNum: null,
        enginplanPermitNum: null,
        landplanPermitNum: null,
        landusePermitNum: null,
        constructiPermitNum: null,
        planPermitNum: null,
        totalLandArea: null,
        totalBuildArea: null,
        buildArea: null,
        startTime: null,
        completTime: null,
        projectBudget: null,
        projectFinalAccounts: null,
        filesCounts: null,
        textVolumes: null,
        drawCounts: null,
        storageTime: null,
        secretLevel: null,
        entryDate: null,
        handoverUnit: null,
        typeId: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null
      },
      // 表单参数
      formEng: {},
      // 表单校验
      rulesEng: {}
    };
  },
  created() {
    this.getListEng();
  },
  methods: {
    /** 查询项目工程管理列表 */
    getListEng() {
      this.queryParamsEng.params = {};
      if (null != this.daterangeStartTime && "" != this.daterangeStartTime) {
        this.queryParamsEng.params["beginStartTime"] = this.daterangeStartTime[0];
        this.queryParamsEng.params["endStartTime"] = this.daterangeStartTime[1];
      }
      if (
        null != this.daterangeCompletTime &&
        "" != this.daterangeCompletTime
      ) {
        this.queryParamsEng.params[
          "beginCompletTime"
        ] = this.daterangeCompletTime[0];
        this.queryParamsEng.params[
          "endCompletTime"
        ] = this.daterangeCompletTime[1];
      }
      if (
        null != this.daterangeStorageTime &&
        "" != this.daterangeStorageTime
      ) {
        this.queryParamsEng.params[
          "beginStorageTime"
        ] = this.daterangeStorageTime[0];
        this.queryParamsEng.params[
          "endStorageTime"
        ] = this.daterangeStorageTime[1];
      }
      if (null != this.daterangeEntryDate && "" != this.daterangeEntryDate) {
        this.queryParamsEng.params["beginEntryDate"] = this.daterangeEntryDate[0];
        this.queryParamsEng.params["endEntryDate"] = this.daterangeEntryDate[1];
      }
      if (null != this.daterangeCreateTime && "" != this.daterangeCreateTime) {
        this.queryParamsEng.params[
          "beginCreateTime"
        ] = this.daterangeCreateTime[0];
        this.queryParamsEng.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      if (null != this.daterangeUpdateTime && "" != this.daterangeUpdateTime) {
        this.queryParamsEng.params[
          "beginUpdateTime"
        ] = this.daterangeUpdateTime[0];
        this.queryParamsEng.params["endUpdateTime"] = this.daterangeUpdateTime[1];
      }
      listEngin(this.queryParamsEng).then(response => {
        this.enginList = response.rows;
        this.totalEng = response.total;
      });
    },
    // 取消按钮
    cancelEng() {
      this.openEng = false;
      this.resetEng();
    },
    // 表单重置
    resetEng() {
      this.formEng = {
        enginId: null,
        enginClassifiNum: null,
        enginFileNum: null,
        enginName: null,
        unitProjectName: null,
        projectLocation: null,
        buildUnit: null,
        constructiUnit: null,
        projectApproveUnit: null,
        designUnit: null,
        surveyUnit: null,
        supervUnit: null,
        qualitySupervUnit: null,
        projectApprovalNum: null,
        enginplanPermitNum: null,
        landplanPermitNum: null,
        landusePermitNum: null,
        constructiPermitNum: null,
        planPermitNum: null,
        totalLandArea: null,
        totalBuildArea: null,
        buildArea: null,
        startTime: null,
        completTime: null,
        projectBudget: null,
        projectFinalAccounts: null,
        filesCounts: null,
        textVolumes: null,
        drawCounts: null,
        storageTime: null,
        secretLevel: null,
        entryDate: null,
        handoverUnit: null,
        typeId: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null
      };
      this.resetForm("formEng");
    },
    /** 搜索按钮操作 */
    handleQueryEng() {
      this.queryParamsEng.pageNum = 1;
      this.getListEng();
    },
    /** 重置按钮操作 */
    resetQueryEng() {
      this.daterangeStartTime = [];
      this.daterangeCompletTime = [];
      this.daterangeStorageTime = [];
      this.daterangeEntryDate = [];
      this.daterangeCreateTime = [];
      this.daterangeUpdateTime = [];
      this.resetForm("queryFormEng");
      this.handleQueryEng();
    },
    // 多选框选中数据
    handleSelectionChangeEng(selection) {
      this.idsEng = selection.map(item => item.enginId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAddEng() {
      this.resetEng();
      this.openEng = true;
      this.titleEng = "添加项目工程管理";
    },
    /** 修改按钮操作 */
    handleUpdateEng(row) {
      this.resetEng();
      const enginId = row.enginId || this.idsEng;
      getEngin(enginId).then(response => {
        this.formEng = response.data;
        this.openEng = true;
        this.titleEng = "修改项目工程管理";
      });
    },
    /** 提交按钮 */
    submitFormEng() {
      this.$refs["formEng"].validate(valid => {
        if (valid) {
          if (this.formEng.enginId != null) {
            updateEngin(this.formEng).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openEng = false;
              this.getListEng();
            });
          } else {
            addEngin(this.formEng).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openEng = false;
              this.getListEng();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDeleteEng(row) {
      const enginIds = row.enginId || this.idsEng;
      this.$modal
        .confirm('是否确认删除项目工程管理编号为"' + enginIds + '"的数据项？')
        .then(function() {
          return delEngin(enginIds);
        })
        .then(() => {
          this.getListEng();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExportEng() {
      this.download(
        "system/engin/export",
        {
          ...this.queryParamsEng
        },
        `engin_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
